<template>
  <el-col class="info-wrapper" :span="23">
    <el-tabs class="table-tabs" type="border-card">
      <el-tab-pane>
        <span slot="label">企业基本信息</span>
        <el-form
          ref="form"
          :model="searchParams"
          label-width="150px"
        >
          <el-col class="search-col">
            <el-form-item label="企业名称：" prop="companyName">
              <div></div>
            </el-form-item>
            <el-form-item label="生产企业名称：" prop="groupId">
              <div></div>
            </el-form-item>
            <el-form-item label="生产企业地址：" prop="contacts">
              <div></div>
            </el-form-item>
          </el-col>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <el-tabs class="table-tabs" type="border-card">
      <el-tab-pane>
        <span slot="label">申请单元</span>
        <el-form
          ref="form"
          :model="searchParams"
          label-width="150px"
        >
          <el-col class="search-col">
            <el-form-item label="认证类型：" prop="companyName">
              <el-select
                v-model="searchParams.province"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in provinceList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="检查目的：" prop="groupId">
              <el-select
                v-model="searchParams.province"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in provinceList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="建档编号：" prop="contacts">
              <el-input style="width: 300px;" v-model="searchParams.groupId"></el-input>
            </el-form-item>
            <el-form-item label="上传附件：" prop="contacts">
              <el-upload
                class="upload-demo"
                action="https://jsonplaceholder.typicode.com/posts/"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                multiple
                :limit="3"
                :on-exceed="handleExceed"
                :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">纸质文件的扫描件</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-form>

        <div v-if="unitList.length === 0" style="margin-left: 40px;margin-top: 40px;">
          <el-link type="primary" :underline="false" @click="addUnitItem">+增加一个申请单元</el-link>
        </div>

        <template v-if="unitList.length > 0">
          <el-form
            v-for="(item, index) in unitList"
            :key="index"
            ref="form"
            :model="unitList[index]"
            label-width="150px"
          >
            <el-col class="unit-item-title" :span="24">申请单元 {{index + 1}}</el-col>
            <el-form-item label="产品单元名称：" prop="contacts">
              <el-input style="width: 300px;" v-model="unitList[index].groupId"></el-input>
            </el-form-item>
            <el-form-item label="产品执行标准号：" prop="contacts">
              <el-input style="width: 300px;" v-model="unitList[index].groupId"></el-input>
            </el-form-item>
            <el-form-item label="商标名称：" prop="contacts">
              <el-input style="width: 300px;" v-model="unitList[index].groupId"></el-input>
            </el-form-item>
            <el-form-item label="申请认证产品等级：" prop="contacts">
              <el-input style="width: 300px;" v-model="unitList[index].groupId"></el-input>
            </el-form-item>
            <el-form-item label="产品认证单元清单：" prop="contacts">
              <el-button type="primary" style="margin-right: 20px;">下载表格导入模版</el-button>
              <el-button type="primary">我要导入</el-button>
            </el-form-item>
            <el-table class="table-tabs" border :data="unitList[index].tableData">
              <el-table-column prop="date" label="产品名称(注明:酒精度）"> </el-table-column>
              <el-table-column prop="date" label="净含量(ml/瓶）"> </el-table-column>
              <el-table-column prop="date" label="注册商标"> </el-table-column>
              <el-table-column prop="date" label="执行标准"> </el-table-column>
              <el-table-column prop="date" label="产品等级"> </el-table-column>
              <el-table-column prop="date" label="内包装材质（瓷瓶或玻瓶）"> </el-table-column>
            </el-table>
            <el-col v-if="unitList.length === index + 1" class="add-unit-btn" :span="24">
              <el-link type="primary" :underline="false" @click="addUnitItem">+增加一个申请单元</el-link>
            </el-col>
            <el-col class="del-unit-btn" :span="24">
              <el-link type="primary" :underline="false" @click="delUnitItem(index)">-删除单元</el-link>
            </el-col>
          </el-form>
        </template>
        <div style="margin-left: 20px;">
          <el-button type="primary" style="margin-right: 20px;">保存为草稿</el-button>
          <el-button type="primary">提交为正式</el-button>
        </div>
      </el-tab-pane>
    </el-tabs>
  </el-col>
</template>

<script>
export default {
  name: "applicantUnitDeatil",
  data() {
    return {
      defulatParams: {
        companyName: "", // 企业名称
        groupId: "", // 组织代码
        province: "", // 省份
        contacts: "", // 联系人
        companyId: "" // 工厂编号
      },
      searchParams: {
        ...this.defulatParams,
      },
      provinceList: [], // 省份列表
      unitList: [],
    };
  },
  mounted() {
    this.queryTableData();
  },
  methods: {
    search() {
      // todo: 搜索方法
    },
    reset() {
      this.searchParams = {
        ...this.defulatParams
      };
      this.search();
    },
    queryTableData() {
      // todo：获取表格数据
    },
    addUnitItem() {
      this.unitList.push({
        tableData: [{ date: 123 }]
      })
    },
    delUnitItem(index) {
      this.unitList.splice(index, 1);
    }
  },
};
</script>

<style lang="less" scoped>
.info-wrapper {
  font-family: Source Han Sans CN;
  font-weight: 400;
  height: 100%;

  .table-tabs {
    margin-top: 15px;
  }

  .unit-item-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
  }

  .add-unit-btn {
    margin-left: 40px;
    margin-top: 20px;
  }

  .del-unit-btn {
    margin: 20px 0px 60px 40px;
  }
}
</style>
